<extend name="Public/base" />
<block name="main">
    <fieldset class="layui-elem-field">
        <legend>微信管理 - 新增配置</legend>
        <div class="layui-field-box">
            <form class="layui-form" action="">
                <if condition="isset($detail['id'])">
                    <input type="hidden" name="id" value="{$detail['id']}">
                </if>
                <if condition="isset($detail['id'])">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">商户名称</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <select name="c_id">
                                <foreach name="list" item="li">
                                    <if condition=" $li.id eq $detail.c_id ">
                                        <option value="{$li.id}" selected>{$li.company_name}</option>
                                    <else/>
                                        <option value="{$li.id}">{$li.company_name}</option>
                                    </if>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <else/>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">应用名称</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <select name="c_id">
                                <volist name="list" id="li">
                                    <option value="{$li['id']}">{$li['company_name']}</option>
                                </volist>
                            </select>

                        </div>
                    </div>
                    </if>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">AppId</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input name="appid" value="{:(isset($detail['appid'])?$detail['appid']:'')}" class="layui-input" placeholder="请输入商户AppId（应用id）">
                    </div>

                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">AppSecret</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input name="appsecret" value="{:(isset($detail['appsecret'])?$detail['appsecret']:'')}"  class="layui-input"  placeholder="请输入商户AppSecret（应用秘钥）">
                    </div>

                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">URL</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input name="url" value="{:(isset($detail['url'])?$detail['url']:'')}"  class="layui-input"   placeholder="请输入URL（服务器地址）">
                    </div>

                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">Token</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input name="token" value="{:(isset($detail['token'])?$detail['token']:'')}"  class="layui-input"  placeholder="请输入Token（令牌）">
                    </div>

                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">EncodingAESKey</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input name="encodingaeskey" value="{:(isset($detail['encodingaeskey'])?$detail['encodingaeskey']:'')}"  class="layui-input"   placeholder="请输入EncodingAESKey（消息加解密秘钥）">
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>
</block>
<block name="myScript">
    <if condition="isset($detail['id'])">
        <input type="hidden" name="id" value="{$detail['id']}">
        <script>
            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(formDemo)', function(data){
                    $.ajax({
                        type: "POST",
                        url: '{:U("edit")}',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });

            });
        </script>
        <else />
        <script>
            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(formDemo)', function(data){
                    $.ajax({
                        type: "POST",
                        url: '{:U("add")}',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });


            });
        </script>
    </if>
</block>